module.exports = {
    webpack: {
        configure(webpackConfig) {
            if (webpackConfig.mode === "production") {
                // 抽离公共代码，只在生产环境
                if (webpackConfig.optimization == null) {
                    webpackConfig.optimization = {}
                }

                webpackConfig.optimization.splitChunks = {
                    chunks: "all",
                    cacheGroups: {
                        antd: {
                            name: "antd-chunk",
                            // 正则表达式，所有引入路径是antd开头的都适用这个规则
                            test: /antd/,
                            priority: 100 // 优先级
                        },
                        reactDom: {
                            name: "reactDom-chunk",
                            // 正则表达式，所有引入路径是react-dom开头的都适用这个规则
                            test: /react-dom/,
                            priority: 99 // 优先级
                        },
                        // 供应商（第三方插件）
                        vendors: {
                            name: "vendors-chunk",
                            test: /node_modules/,
                            priority: 98
                        }
                    }
                }
            }
            return webpackConfig
        }
    },
    devServer: {
        port: 8000,
        proxy: {
            // 所有以 /api开头的路由都指向http://localhost:3001
            "/api": "http://localhost:3001"
        }
    }
}
